var viewHost="http://www.bnncar.com";
var emptyPic="/img/nopic.gif";

var page={};



function cnCookie(n)
{
	var s=$.cookie(n);if(!s) return "";
	var l=$.cookie(n).split("|");s="";
	for(var i=0;i<l.length;i++)	{s+=String.fromCharCode(parseInt(l[i],16));	}
	return s;
}
function isLogin()
{
	var v=$.cookie('islogin');
	if(v=="Y") 
		return true;
	else 
		return false;
}
function exSubMenu(n,o)
{
	var disp=document.getElementById("lmul"+n).style.display;
	if(disp=="none") 
	{
		$("#lmul"+n).slideDown("slow");
	}
	else 
	{	
		$("#lmul"+n).slideUp("slow");
	}
}
function onMenu(o)
{
	var cn=o.className;
	if(cn=="lm0") o.className="lm1";
	if(cn=="lm1") o.className="lm0";
}
function setMenu(n0,n1)
{
	document.getElementById("menu"+n0).className="top11";
	document.getElementById("lm"+n0).className="lm2";
	document.getElementById("sm"+n0+n1).className="li0";
}
function showWarning (code,msg,width,height)
{	
	if(width==undefined) width=150;
	var $msg = $("<div class='tips'><div class='tips-wrap' style='width:"+width+"px;height:"+height+"px'>"+msg+"</div></div>");
	$("body").find(".tips").remove().end().append($msg);
}

//////////////////////////////

function scroTop()
{
	parent.window.scroll(0,0);
}
function onTR(o,v){if(o.className!="tr2")o.className="tr"+v;}
function clickTR(o){o.className=(o.className=="tr2"?"tr1":"tr2");}
function dbClickTR(o){var po=o.parentNode;var arr=po.getElementsByTagName("TR");var l=arr.length;for(var i=0;i<l;i++){arr[i].className="tr0";}}
function onBtn(o,v){o.className="btn"+v;}
function onSBtn(o,v){o.className="sbtn"+v;}
function onTxt(o,v){o.className="txt"+v;}
function IsDigit(){return ((event.keyCode >= 48) && (event.keyCode <= 57));}
function setMaxPage(maxPage) {
    $('#pages').attr('maxPage',maxPage);
}
function getMaxPage() {
   return parseInt($('#pages').attr('maxPage'));
}

function pageTurn(curPage)
{
	if(page.callbakFunc){
        page.callbakFunc(curPage);
	}
	// var maxPage=getMaxPage(),oid='pages';
	// drawPage(maxPage,curPage,'pages')
}
function intiPage(maxPage,curPage,pageItemClick) {
	setMaxPage(maxPage);
	page.callbakFunc=pageItemClick;
    drawPage(maxPage,curPage,'pages')
}
function drawPage(maxPage,curPage,oid)
{
	var str="";
	if(curPage>=1) 
	{
		if(curPage>1) str+="<a class='next' style='margin-right:5px' onclick='pageTurn("+(curPage-1)+")'><</a>";
		if(curPage>3) str+="<a onclick='pageTurn(1)'>1</a>";
		if(curPage-2>1) str+="<span>...</span>";
		var start=curPage-2>1?curPage-2:1,end=curPage+2<=maxPage?curPage+2:maxPage;
		for(var i=start;i<=end;i++){str+="<a"+(i==curPage?" class='cur'":" onclick=\"pageTurn("+i+")\"")+">"+i+"</a>";}
		if(curPage+2<maxPage) str+="<span>...</span><a onclick='pageTurn("+maxPage+")'>"+maxPage+"</a>";		
		if(curPage<maxPage) str+="<a onclick='pageTurn("+(curPage+1)+")' class='next' style='margin:0 10px 0 5px'>></a>";
		if(maxPage>1)
			str+="跳转至<input type='text' class='pagetxt' id='pageTxt' onkeypress='return isNumber()'> <input type='button' class='btn0' value='确定' onclick='toPageClick()'></input>";
		else
            str+="跳转至<input type='text' class='pagetxt' id='pageTxt' disabled='disabled'> <button class='btn0' disabled='disabled')>确定</button>";
	}
	else
	{
		str+="共0页";
	}
	$("#"+oid).html(str);
}
function toPageClick() {
    var toPage = parseInt($('#pageTxt').val());
    if (toPage > getMaxPage() || toPage <= 0) {
        return;
    }
    pageTurn(toPage);
}
function getPos(e) 
{
 var t=e.offsetTop;  
 var l=e.offsetLeft;  
 while(e=e.offsetParent) 
 {  
  t+=e.offsetTop;  
  l+=e.offsetLeft;  
 }  
 var rec = new Array(1); 
 rec[0]=l; 
 rec[1]=t; 
 return rec;
}
function setDat(v)
{
	if(v=="0001-01-01") this.innerHTML="-";
	else  this.innerHTML=v;
}
function pmuserDetail(id,v){document.write("<a href='/pmuser_view.shtml?id="+id+"' target=_blank>"+v+"</a>");}
function purchaseDetail(id,v){document.write("<a href='/purchase_view.shtml?id="+id+"' target=_blank>"+v+"</a>");}
function userDetail(id,v){document.write("<a href='/user_view.shtml?id="+id+"' target=_blank>"+v+"</a>");}
function ordersDetail(id,v)	
{
	var w=900
	var h=750
	popWin.scrolling="yes";
	popWin.showWin(w,h,"订单详情","/orders_view.html?id="+id);
}

//////////////////
function setGoodsStat(v)
{
	switch(v)
	{
		case 1:this.innerHTML="上架";break;
		case 2:this.innerHTML="下架";break;
		case 3:this.innerHTML="编辑中";break;
	}
}
function setStat(v)
{
	switch(v)
	{
		case 1:this.innerHTML="显示";break;
		case 2:this.innerHTML="<font color=red>屏蔽</font>";break;
		case 3:this.innerHTML="<font color=red>编辑中</font>";break;
		default:this.innerHTML="<font color=red>异常</font>";break;
	}
}
function setOrderStat(v)
{
	this.innerHTML="";
	for(var i=0;i<code_orderstat_arr.length;i++)
	{
		if(code_orderstat_arr[i][0]==v)
		{
			this.innerHTML=code_orderstat_arr[i][1];break;
		}
	}
}
/////////////////
function setMoney(v)
{
	this.innerHTML="￥"+v;
}
function setNumber(v)
{
	this.innerHTML=formatNumber(v)
}
function formatNumber(v)
{
	var ret="";
	while(true)
	{	
		if(ret!="") ret=","+ret;
		if(v<1000)
		{
			ret=v.toString()+ret;
			if(ret.indexOf(".")>0)
			{
				ret=ret.substr(0,ret.indexOf("."));
			}
			return ret;
		}
		var m=v%1000;
		ret=(m>=100?m:(m>=10?"0"+m.toString():"00"+m.toString()))+ret;
		v=parseInt(v/1000);
	}
}

function purchaseImgDetail(url)
{
    var w=1500;
    var h=820;
    popWin.scrolling="no";
    popWin.showWin(w,h,"图片编辑","http://test.zuzhiweiyuan.com/purchase_img.html?url="+url);
}

function sel_init(arr,o)
{
    if(!o) return;
    var minL=o.getAttribute("min");
    if(minL)o.options.length=minL;
    for(var i=0;i<arr.length;i++)
        o.options[o.length]=new Option(arr[i][1],arr[i][0]);
}


